package com.qtu.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * BCrypt:密码加密
 */
public class BCryptUtil {

    private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    /**
     * 加密
     * @param password 明文密码
     * @return
     */
    public static String encode(String password){
       return passwordEncoder.encode(password);
    }

    /**
     * 判断密码是否一致
     * @param newPassword 新密码
     * @param oldPassword 老密码
     * @return
     */
    public static boolean matches(String newPassword,String oldPassword){
        return passwordEncoder.matches(newPassword,oldPassword);
    }
}
